package com.masc.gurr.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Session {
	
	private History fHistoryParentRef;
	private ArrayList<Message> fListMessages;
	private long fLongSid;
	private String fStrBuddyUin;
	private String fStrMyUin;
	private ProtocolType fProtocolType;
	private Map<Long, Message> fMapIdMessage;
	private long fCurrMsgId;
	
	public Session(String pStrBuddyUin, History pHistoryParent, String pStrMyUin, ProtocolType pProtocolType, long pLongSid) {
		fListMessages=new ArrayList<Message>();
		fHistoryParentRef=pHistoryParent;
		fStrBuddyUin=pStrBuddyUin;
		fStrMyUin = pStrMyUin;
		fProtocolType=pProtocolType;
		fLongSid = pLongSid;
		fMapIdMessage = new HashMap<Long, Message>();
		fCurrMsgId=0;
	}
	
	public void addMessage(String pStrUin, String pStrMsg, Date pDate) {
		Message m = new Message(pStrUin, pStrMsg, pDate, fCurrMsgId);
		fListMessages.add(m);
		fMapIdMessage.put(fCurrMsgId, m);
		fCurrMsgId++;
	}
	
	public void addMessage(String pStrUin, String pStrMsg, Date pDate, long pCurrMsgId) {
		Message m = new Message(pStrUin, pStrMsg, pDate, pCurrMsgId);
		fListMessages.add(m);
		fMapIdMessage.put(pCurrMsgId, m);
		fCurrMsgId++;
	}
	
	public void removeMessage(long pLongMsgId) {
		Message m = fMapIdMessage.get(pLongMsgId);
		if (m != null)
			fListMessages.remove(m);
		fMapIdMessage.remove(pLongMsgId);
	}
	
	public ArrayList<Message> getMessages() {
		return fListMessages;
	}
	
	public Iterator<Message> getMessageIterator() {
		return fListMessages.iterator();
	}
	
	public long getSid() {
		return fLongSid;
	}
	
	public void setSid(long pLongSid) {
		fLongSid = pLongSid;
	}
	
	public String getMyUin() {
		return fStrMyUin;
	}
	
	public History getParentHistory() {
		return fHistoryParentRef;
	}
	
	public void setParentHistory(History pHistoryParentRef) {
		fHistoryParentRef = pHistoryParentRef;
	}
	
	public String getBuddyUin() {
		return fStrBuddyUin;
	}
	
	public ProtocolType getProtocolType() {
		return fProtocolType;
	}
	
	public Map<Long, Message> getMapIdMsg() {
		return fMapIdMessage;
	}

	public void setSetCurrMsgId(long currMsgId) {
		fCurrMsgId=currMsgId;
	}
}
